namespace Radar
{
    using System;

    internal sealed class ConstantFactoryBuilder : IFactoryBuilder
    {
        private readonly Func<object> factoryMethod;
        private readonly IConfigurationProvider configurationProvider;

        public ConstantFactoryBuilder(IConfigurationProvider configurationProvider, Func<object> factoryMethod)
        {
            if (configurationProvider == null) throw new ArgumentNullException("configurationProvider");
            if (factoryMethod == null) throw new ArgumentNullException("factoryMethod");

            this.factoryMethod = factoryMethod;
            this.configurationProvider = configurationProvider;
        }

        public Func<ResolveContext, object> GetFactoryMethod(params Type[] arguments)
        {
            return configurationProvider.Lifetime.GetBuilder(c => factoryMethod());
        }
    }
}